<?php

/**
 * OntoWiki bookmarklet module template
 *
 * @author     Sebastian Dietzold <dietzold@informatik.uni-leipzig.de>
 * @copyright  Copyright (c) 2009, {@link http://aksw.org AKSW}
 * @license    http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
 */

?>
<?php if ($this->has('warningMessage')): ?>
    <p class="messagebox info"><?php echo $this->warningMessage ?></p>
<?php endif; ?>
<?php if ($this->has('infoMessage')): ?>
    <p class="messagebox info"><?php echo $this->infoMessage ?></p>
<?php endif; ?>
<script type="text/javascript" charset="utf-8">
    var saveTitle = 'Save to OntoWiki';
    var windowTitle = 'Extract Triples to OntoWiki at <?php echo $this->ontoWikiUrl ?>';
    // var bmWidgetBase = document.location.href.replace('tests/bookmarklet.html', '');
    var bmWidgetBase = '<?php echo $this->rdfAuthorBase ?>';
    var href = '\
        href="javascript:void((function() {\
        RDFAUTHOR_BASE = \'' + bmWidgetBase + '\';\
        RDFAUTHOR_DEFAULT_GRAPH = \'<?php echo $this->defaultGraph ?>\';\
        RDFAUTHOR_DEFAULT_UPDATE_ENDPOINT = \'<?php echo $this->defaultUpdateService ?>\';\
        RDFAUTHOR_DEFAULT_QUERY_ENDPOINT = \'<?php echo $this->defaultQueryService ?>\';\
        RDFAUTHOR_READY_CALLBACK = function() {\
            RDFauthor.setOptions({\
                saveButtonTitle: saveTitle,\
                cancelButtonTitle: \'Cancel\',\
                title: windowTitle,\
                showAddPropertyButton: false\
            });\
            RDFauthor.start();\
        };\
        load = function() {\
            var s = document.createElement(\'script\');\
            s.type = \'text/javascript\';\
            s.id = \'rdfauthor-script\';\
            s.src = RDFAUTHOR_BASE + \'src/rdfauthor.js\';\
            document.getElementsByTagName(\'head\')[0].appendChild(s);\
        };\
        if (typeof jQuery == \'undefined\') {\
            var j = document.createElement(\'script\');\
            j.type = \'text/javascript\';\
            j.src = RDFAUTHOR_BASE + \'libraries/jquery.js\';\
            j.onload = load;\
            document.getElementsByTagName(\'head\')[0].appendChild(j);\
        } else {\
            if (!document.getElementById(\'rdfauthor-script\')) {\
                load();\
            }\
        }\
    })());"';
    
    // rebuild strings
    document.writeln('<a ' + 
        href.replace(/[\s]/g, '')
            .replace('saveTitle', '\'' + saveTitle + '\'')
            .replace('windowTitle', '\'' + windowTitle + '\'')
            .replace('varj', 'var j').replace('vars', 'var s').replace('vars', 'var s')
            .replace('typeofjQuery', 'typeof jQuery') + 
        '>Save to OntoWiki with RDFauthor</a>');
</script>
